package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzAgentGrade;
import com.zzedu.dto.AgentGradeDTO;
import com.zzedu.service.IZzAgentGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 代理商等级Controller
 * 
 * @author Mr.Wang
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/agent/grade")
public class ZzAgentGradeController extends BaseController
{
    @Autowired
    private IZzAgentGradeService agentGradeService;

    /**
     * 查询代理商等级列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody AgentGradeDTO agentGrade)
    {
        return getDataTable(agentGradeService.page(agentGrade.getPageDTO(),agentGradeService.buildQuery(agentGrade)));
    }

    /**
     * 导出代理商等级列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:export')")
    @Log(title = "代理商等级", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public AjaxResult export(AgentGradeDTO agentGrade)
    {
        List<ZzAgentGrade> list = agentGradeService.list(agentGradeService.buildQuery(agentGrade));
        ExcelUtil<ZzAgentGrade> util = new ExcelUtil<ZzAgentGrade>(ZzAgentGrade.class);
        return util.exportExcel(list, "代理商等级数据");
    }




    /**
     * 新增保存代理商等级
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:add')")
    @Log(title = "代理商等级", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@RequestBody ZzAgentGrade zzAgentGrade)
    {
        return toAjax(agentGradeService.save(zzAgentGrade));
    }



    /**
     * 获取代理商等级详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(agentGradeService.getById(id));
    }


    /**
     * 修改保存代理商等级
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:edit')")
    @Log(title = "代理商等级", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@RequestBody ZzAgentGrade zzAgentGrade)
    {
        return toAjax(agentGradeService.updateById(zzAgentGrade));
    }

    /**
     * 删除代理商等级
     */
    @PreAuthorize("@permission.hasAnyPermissions('agent:grade:remove')")
    @Log(title = "代理商等级", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(agentGradeService.removeBatchByIds(ids));
    }
}
